package models;

import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;

import play.data.binding.As;
import play.data.validation.Required;
import play.db.jpa.Model;
import utils.check.ConnectedUserAnno;

/**
 * Class for table ReadingSheet.
 * @author Elisa
 */
@Entity
public class ReadingSheet extends Model {

	
	@Required
	@ConnectedUserAnno
	@ManyToOne//(fetch = FetchType.EAGER)
	public User user;
	@Required
	@ManyToOne
	public Book book;
	public Integer grade;
	@As(value={"dd/MM/yyyy", "dd-MM-yyyy", "ddMMyyyy", "MM/yyyy", "MM-yyyy", "MMyyyy", "MM yyyy", "MMMMM yyyy"})
	public Date readingdate;
	public String origin;
	
	@Lob
	public String comment;
	@Lob
	public String resume;
	@Lob
	public String beginning;
	@Lob
	public String piece; //extract
	public String piecePage;
	
	@Required
	public Integer right;
	
	
	/**
	 * Constructor with user. Right is set to 0.
	 * @param user
	 */
	public ReadingSheet(final User user) {
		this.user = user;
		this.right = 0;
	}
	
	/**
	 * Constructor with user and book. Right is set to 0.
	 * @param user
	 * @param book
	 */
	public ReadingSheet(final User user, final Book book) {
		this.user = user;
		this.book = book;
		this.right = 0;
	}
	

	/**
	 * Constructor with all fields.
	 * @param user
	 * @param book
	 * @param grade
	 * @param readingdate
	 * @param origin
	 * @param comment
	 * @param resume
	 * @param beginning
	 * @param piece
	 * @param piecePageNb
	 * @param right
	 */
	public ReadingSheet(final User user, final Book book, final Integer grade, final Date readingdate, final String origin, final String comment,
			final String resume, final String beginning, final String piece, final String piecePage, final Integer right) {
		super();
		this.user = user;
		this.book = book;
		this.grade = grade;
		this.readingdate = readingdate;
		this.origin = origin;
		this.comment = comment;
		this.resume = resume;
		this.beginning = beginning;
		this.piece = piece;
		this.piecePage = piecePage;
		this.right = right;
	}	
	
}
